//
//  RecommendNormalDetail.m
//  AutoHome
//
//  Created by wqh on 15-5-15.
//  Copyright (c) 2015年 Wqh. All rights reserved.
//

#import "RecommendNormalDetail.h"

@interface RecommendNormalDetail ()<UIWebViewDelegate>
@property (nonatomic) UIActivityIndicatorView *activityIndicator;
@end

@implementation RecommendNormalDetail

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor customGrayColor];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBar.translucent = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    
    self.webView.delegate = self;
    
    [self.view addSubview:self.webView];
    
    [self downloadData];
    
}

- (void)downloadData {
    
    if (self.url) {
        
        [[DataEngine sharedInstance] requestSpecialWebViewDataWith:self.url id:self.model.id success:^(id respondsData) {
            [self downloadDataSuccess:respondsData];
        } failed:^(NSError *error) {
            
        }];
    }else {
        [[DataEngine sharedInstance] requestWebViewDataWithId:self.model.id success:^(id respondsData) {
            [self downloadDataSuccess:respondsData];
        } failed:^(NSError *error) {
            
        }];
    }
}

- (void)downloadDataSuccess :(id)respondsData {
    NSString *htmlStr = [[NSString alloc] initWithData:respondsData encoding:NSUTF8StringEncoding    ];
    [self.webView loadHTMLString:htmlStr baseURL:nil];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [self.activityIndicator setCenter:self.webView.center];
    [self.activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [self.webView addSubview:self.activityIndicator];
    
    [self.activityIndicator startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.activityIndicator stopAnimating];
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
